<template>
	<view class="login-content">
		<view class="back" @click="toBack">
			<image src="../../static/image/index/back-black.png" mode=""></image>
		</view>
		<view class="title">
			重置密碼
		</view>
		<view class="tips" style="opacity: 0;">
			還沒有賬號，<text style="color:#0055ff">立即註冊</text>
		</view>
		<view class="infor-content">
			<view class="item">
				<input type="tel" v-model="tel" placeholder-style="color:#9E9E9E" placeholder="请输入手机号">
			</view>
			<view class="item">
				<input type="text" v-model="code" placeholder="请输入驗證碼" placeholder-style="color:#9E9E9E" >
				<view class="send-code" v-if="!haveSend" @click="sendCode">發送驗證碼</view>
				<view class="countDown" @click="sendCode" v-if="haveSend">
					重新發送<text v-if="countNum>0">（{{countNum}}s）</text>
				</view>
			</view>
			<view class="item">
				<input type="password" v-model="password" placeholder-style="color:#9E9E9E" placeholder="请输入新密碼">
			</view>
		</view>
		<view class="login-btn">
			更改密碼
		</view>
	</view>
</template>

<script>
	import { changePassword } from '../../request/api.js'
	export default {
		data() {
			return {
				tel:'',
				password:'',
				code:"",
				haveSend:false,
				countNum:0,
			};
		},
		methods:{
			toBack(){
				uni.navigateBack()
			},
			backLogin(){
				uni.navigateBack()
			},
			// 发送验证码
			sendCode(){
				if(this.countNum>0){
					return;
				}
				this.haveSend=true;
				this.countNum=60;
				let timeInter=setInterval(()=>{
					if(this.countNum>0){
						this.countNum--;
					}else{
						clearInterval(timeInter);
					}
				},1000)
			},
			//确定修改密码
			async changeOk(){
				if(!this.tel){
					uni.showToast({
						title: '請填寫手機號',
						icon: 'none'
					})
					return
				}
				if (!/^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/.test(this.tel)){
					uni.showToast({
						title: '請填寫正確手機號',
						icon: 'none'
					})
					return
				}
				if(!this.password){
					uni.showToast({
						title: '請填寫新密碼',
						icon: 'none'
					})
					return
				}
				if(!this.code){
					uni.showToast({
						title: '請填寫驗證碼',
						icon: 'none'
					})
					return
				}
				uni.showLoading({
					title:'修改中...'
				})
				let res=await changePassword({
					mobile:this.tel,
					captcha:this.code,
					newpassword:this.password
				})
				console.log(res);
				uni.hideLoading();
				if(res.code==1){
					uni.showToast({
						title: '修改成功',
						icon: 'none'
					})
					uni.navigateBack()
				}else{
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	page{
		background-color: #FAFAFA;
		.back{
			width:60rpx;height:60rpx;position: absolute;
			top:70rpx;left:20rpx;
			image{
				width:60rpx;height:60rpx;
			}
		}
		.login-content{
			width:650rpx;margin-left:auto;
			margin-right:auto;
			padding-top:190rpx;
			.title{
				font-size: 40rpx;line-height:56rpx;
				color:#040404;
			}
			.tips{
				font-size:24rpx;line-height:33rpx;
				color:#9E9E9E;margin-top:15rpx;
			}
			.infor-content{
				margin-top:130rpx;
				.item{
					padding:40rpx 0;border-bottom:1px solid #F0F0F0;
					display: flex;align-items: center;
					input{
						font-size:28rpx;color:#333333;flex:1;
					}
					.send-code{
						font-size: 28rpx;color:#333333;
					}
					.countDown{
						font-size: 28rpx;color:#D71B0A;
					}
				}
			}
			.login-btn{
				width:100%;height:98rpx;border-radius: 98rpx;
				display: flex;align-items: center;justify-content: center;
				font-size:36rpx;color:#ffffff;background-color:#040404;
				margin-top:120rpx;
			}
			.to-login{
				margin-top:30rpx;font-size:28rpx;color:#9E9E9E;
				line-height:40rpx;text-align: center;
			}
			.agreement{
				display: flex;align-items:center;position: absolute;left:0;
				bottom:50rpx;width:100%;justify-content: center;
				font-size:24rpx;color:#9E9E9E;
				.choose{
					width:26rpx;height:26rpx;border-radius: 50%;
					border:1px solid #9E9E9E;box-sizing: border-box;
					margin-right:10rpx;
				}
				text{
					color:#040404
				}
				.checked{
					width:26rpx;height:26rpx;margin-right:10rpx;
					image{
						width:26rpx;height:26rpx;
					}
				}
			}
		}
	}
</style>
